package com.dly.blog.controller;

import com.dly.blog.domain.vo.permission.PermissionListVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dly.blog.controller.BaseController;
import lombok.AllArgsConstructor;
import com.dly.blog.domain.vo.permission.PermissionVO;
import com.dly.blog.domain.ro.permission.PermissionPageRO;
import com.dly.blog.domain.ro.permission.PermissionAddRO;
import com.dly.blog.domain.ro.permission.PermissionEditRO;
import com.dly.blog.service.PermissionService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.dly.blog.domain.vo.PageVO;
import com.dly.blog.msg.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author DLY
 * @since 2024-11-13 15:16:31
 */
@Tag(name = "权限相关")
@AllArgsConstructor
@RestController
@RequestMapping("/user/permission")
public class PermissionController extends BaseController {

    private final PermissionService permissionService;


    @GetMapping(value = "/all")
    @Operation(summary = "分页获取权限信息")
    public ResponseEntity<R<List<PermissionListVO>>> getPermissionList(){
        return operate(()-> this.successDate(permissionService.getPermissionList()));
    }

    @PostMapping(value = "/page")
    @Operation(summary = "分页获取权限信息")
    public ResponseEntity<R<PageVO<PermissionVO>>> getPermissionPage(@RequestBody PermissionPageRO permissionPageRO){
        return operate(()-> this.successDate(permissionService.getPermissionPage(permissionPageRO)));
    }

    @PostMapping(value = "/add")
    @Operation(summary = "添加权限信息")
    public ResponseEntity<R<Void>> addPermission(@RequestBody PermissionAddRO permissionAddRO){
        permissionService.addPermission(permissionAddRO);
        return operate(this::success);
    }

    @PostMapping(value = "/edit")
    @Operation(summary = "修改权限信息")
    public ResponseEntity<R<Void>> editPermission(@RequestBody PermissionEditRO permissionEditRO){
        permissionService.editPermission(permissionEditRO);
        return operate(this::success);
    }

    @PostMapping(value = "/get/{id}")
    @Operation(summary = "获取权限信息")
    public ResponseEntity<R<PermissionVO>> getPermission(@PathVariable(value = "id") String id){
        return operate(()-> this.successDate(permissionService.getPermission(id)));
    }

    @PostMapping(value = "/remove/{ids}")
    @Operation(summary = "删除权限信息")
    public ResponseEntity<R<Void>> removePermission(@PathVariable(value = "ids") String[] ids){
        permissionService.removePermission(ids);
        return operate(this::success);
    }

}
